<!--********************************************************************
* 该示例需要引入 
* maplibre-gl-enhance (https://iclient.supermap.io/web/libs/maplibre-gl-js-enhance/4.3.0-1/maplibre-gl-enhance.js)
*********************************************************************-->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
        <title data-i18n="resources.title_graticuleLayer_4326"></title>
        <script type="text/javascript" src="../js/include-web.js"></script>
        <script
            type="text/javascript"
            include="maplibre-gl-enhance"
            src="../../dist/maplibregl/include-maplibregl.js"
        ></script>
        <style>
            body {
                margin: 0;
                padding: 0;
            }

            #map {
                position: absolute;
                top: 0;
                bottom: 0;
                width: 100%;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>
        <script type="text/javascript">
            var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
            var map = new maplibregl.Map({
                container: 'map', // container id
                style: {
                    version: 8,
                    sources: {
                        'raster-tiles': {
                            type: 'raster',
                            tileSize: 256,
                            tiles: [host + '/iserver/services/map-world/rest/maps/World'],
                            rasterSource: 'iserver'
                        }
                    },

                    layers: [
                        {
                            id: 'simple-tiles',
                            type: 'raster',
                            source: 'raster-tiles',
                            minzoom: 0,
                            maxzoom: 22
                        }
                    ]
                },
                crs: 'EPSG:4326',
                center: [0, 0],
                zoom: 2
            });
            map.on('load', function() {
                //从 iServer 查询
                var idsParam = new maplibregl.supermap.GetFeaturesByIDsParameters({
                    IDs: [234],
                    datasetNames: ['World:Countries']
                });
                var service = new maplibregl.supermap.FeatureService(host + '/iserver/services/data-world/rest/data');
                service.getFeaturesByIDs(idsParam).then(function(serviceResult) {
                    map.addSource('queryDatas', {
                        type: 'geojson',
                        data: serviceResult.result.features
                    });
                    map.addLayer({
                        id: 'queryDatas',
                        type: 'fill',
                        source: 'queryDatas',
                        paint: {
                            'fill-color': '#008080',
                            'fill-opacity': 0.4
                        },
                        filter: ['==', '$type', 'Polygon']
                    });
                });
                // 设置经纬网
                var graticuleLayer = new maplibregl.supermap.GraticuleLayer();
                map.addLayer(graticuleLayer);
            });
        </script>
    </body>
</html>
